Error when leaving field blank or default

Help with error...If I leave the first field "UOM" to default or erase contents and leave it blank I get an error. If I enter something for all 4 of them it works fine. Any help would be appreciated.

The error I get is -R-E- DXL: <Line:32> unassigned variable (simple)

//global variable
string sUom
string sMin
string sMax
string sPrec

DBE uom
DBE min
DBE max
DBE prec

Module m = current
//func declaration

void create_filter(DBE dbe) {

sUom = get uom
sMin = get min
sMax = get max
sPrec = get prec

Filter simple

if ((sUom != "<enter UOM to search>") && (sUom != null))
{
simple = contains(attribute "Format/Values", sUom, false)
}
//if a user input a min value
if ((sMin != "<enter numeric value>") && (sMin != null))
{
if (null simple)
{
simple = contains(attribute "Format/Values", sMin, false)
}
else //simple indicates filter
{
simple = simple && contains(attribute "Format/Values", sMin, false)
}
}

if ((sMax != "<enter numeric value>") && (sMax != null))
{

simple = simple && contains(attribute "Format/Values", sMax, false)
}

if ((sPrec != "<enter numeric value after \".\": ex: \".01\">") && (sPrec != null))
{
simple = simple && contains(attribute "Format/Values", sPrec, false)
}

set simple
filtering on
applyFiltering (m)
refresh m

print("Done")

}

void filter_off(DBE dbe) {
filtering off
refresh m

}

//---------------------------------------------------------------------
// main
DB b = create((NLS_("Domain Search Tool")), styleThemed|styleAutoparent)

uom = field(b, (NLS_("Units of Measure:")), (NLS_("<enter UOM to search>")), 31)
min = field(b, (NLS_("Range Minimum:")), (NLS_("<enter numeric value>")), 31)
max = field(b, (NLS_("Range Maximum:")), (NLS_("<enter numeric value>")), 31)
prec = field(b, (NLS_("Precision:")), (NLS_("<enter numeric value after \".\": ex: \".01\">")), 31)
//DBE englishPresentation = field(b, (NLS_("English Presentation:")), (NLS_("<enter English presentation:>")), 31)

button(b, (NLS_("Search")), create_filter)
button(b, (NLS_("Filter Off")), filter_off)
show b

//----------------------------------------------------------------------
vppatel - Tue May 11 15:04:30 EDT 2010

Re: Error when leaving field blank or default
johnzweck - Wed May 12 10:37:14 EDT 2010

For some reason, DXL doesn't recognize an uninitiated filter as being null. Try changing your filter definition to:

Filter simple = null

 


John

 

Re: Error when leaving field blank or default
vppatel - Wed May 12 12:44:01 EDT 2010

johnzweck - Wed May 12 10:37:14 EDT 2010

For some reason, DXL doesn't recognize an uninitiated filter as being null. Try changing your filter definition to:

Filter simple = null

 


John

 

Tried that, still didn't work.

Re: Error when leaving field blank or default
Mathias Mamsch - Wed May 12 16:10:10 EDT 2010

uhm ... looking at your code I find it not really surprising that in some cases simple is uninitialized ... What happens for example if the first two conditions, where you set your simple filter in the create_filter function are not met? See comments in code below ...

Regards, Mathias
 

// uninitialized
    Filter simple
 
    sMin = get min
    sUom = get uom
 
    if ((sUom != "<enter UOM to search>") && (sUom != null)) { 
    // set simple
    }
    
    if ((sMin != "<enter numeric value>") && (sMin != null)) {
    // set simple
    }
 
    // If sMin and sUom are empty, null or have their initial value simple will STILL be unitnitialized here
 
    if ((sMax != "<enter numeric value>") && (sMax != null)) {
        // ouch ... simple is uninitialized
        simple = simple && ... 
    }

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

Re: Error when leaving field blank or default
vppatel - Wed May 12 16:32:16 EDT 2010

Mathias Mamsch - Wed May 12 16:10:10 EDT 2010

uhm ... looking at your code I find it not really surprising that in some cases simple is uninitialized ... What happens for example if the first two conditions, where you set your simple filter in the create_filter function are not met? See comments in code below ...

Regards, Mathias
 

// uninitialized
    Filter simple
 
    sMin = get min
    sUom = get uom
 
    if ((sUom != "<enter UOM to search>") && (sUom != null)) { 
    // set simple
    }
    
    if ((sMin != "<enter numeric value>") && (sMin != null)) {
    // set simple
    }
 
    // If sMin and sUom are empty, null or have their initial value simple will STILL be unitnitialized here
 
    if ((sMax != "<enter numeric value>") && (sMax != null)) {
        // ouch ... simple is uninitialized
        simple = simple && ... 
    }

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

So it works this way, but if I leave UOM blank it searches for that blank but I don't want it to search for a blank if nothing is entered in that field or is left to default. If I do other cases like leave Rmax or Rmin blank or default it works fine, just not with the first UOM. Hopefully what I wrote makes sense.....and Thanks for the help....
 

//global variable
string sUom
string sMin
string sMax
string sPrec
 
DBE uom
DBE min
DBE max
DBE prec
 
Module m = current
//func declaration
 
void create_filter(DBE dbe) {
 
sUom = get uom
sMin = get min
sMax = get max
sPrec = get prec
 
Filter simple
 
    if (sUom != "<enter UOM to search>")
        {
                simple = contains(attribute "Format/Values", sUom, false)
        }
        //if a user input a min value
        if ((sMin != "<enter numeric value>") && (sMin != null))
        {
                if (null simple)
                {
                        simple = contains(attribute "Format/Values", sMin, false)
                }
                else //simple indicates filter
                {
                        simple = simple && contains(attribute "Format/Values", sMin, false)
                }
        }
 
        if ((sMax != "<enter numeric value>") && (sMax != null))
        {
 
                simple = simple && contains(attribute "Format/Values", sMax, false)
        }
 
        if ((sPrec != "<enter numeric value after \".\": ex: \".01\">") && (sPrec != null))
        {
                simple = simple && contains(attribute "Format/Values", sPrec, false)
        }
 
set simple
filtering on
applyFiltering (m)
refresh m
 
print("Done")
 
}
 
void filter_off(DBE dbe) {
filtering off
refresh m
 
}
 
//---------------------------------------------------------------------
// main
 
DB b = create((NLS_("Domain Search Tool")), styleThemed|styleAutoparent)
 
uom = field(b, (NLS_("Units of Measure:")), (NLS_("<enter UOM to search>")), 31)
min = field(b, (NLS_("Range Minimum:")), (NLS_("<enter numeric value>")), 31)
max = field(b, (NLS_("Range Maximum:")), (NLS_("<enter numeric value>")), 31)
prec = field(b, (NLS_("Precision:")), (NLS_("<enter numeric value after \".\": ex: \".01\">")), 31)
//DBE englishPresentation = field(b, (NLS_("English Presentation:")), (NLS_("<enter English presentation:>")), 31)
 
button(b, (NLS_("Search")), create_filter)
button(b, (NLS_("Filter Off")), filter_off)
show b
 
//----------------------------------------------------------------------

Re: Error when leaving field blank or default
Mathias Mamsch - Thu May 13 07:58:34 EDT 2010

vppatel - Wed May 12 16:32:16 EDT 2010

So it works this way, but if I leave UOM blank it searches for that blank but I don't want it to search for a blank if nothing is entered in that field or is left to default. If I do other cases like leave Rmax or Rmin blank or default it works fine, just not with the first UOM. Hopefully what I wrote makes sense.....and Thanks for the help....
 

//global variable
string sUom
string sMin
string sMax
string sPrec
 
DBE uom
DBE min
DBE max
DBE prec
 
Module m = current
//func declaration
 
void create_filter(DBE dbe) {
 
sUom = get uom
sMin = get min
sMax = get max
sPrec = get prec
 
Filter simple
 
    if (sUom != "<enter UOM to search>")
        {
                simple = contains(attribute "Format/Values", sUom, false)
        }
        //if a user input a min value
        if ((sMin != "<enter numeric value>") && (sMin != null))
        {
                if (null simple)
                {
                        simple = contains(attribute "Format/Values", sMin, false)
                }
                else //simple indicates filter
                {
                        simple = simple && contains(attribute "Format/Values", sMin, false)
                }
        }
 
        if ((sMax != "<enter numeric value>") && (sMax != null))
        {
 
                simple = simple && contains(attribute "Format/Values", sMax, false)
        }
 
        if ((sPrec != "<enter numeric value after \".\": ex: \".01\">") && (sPrec != null))
        {
                simple = simple && contains(attribute "Format/Values", sPrec, false)
        }
 
set simple
filtering on
applyFiltering (m)
refresh m
 
print("Done")
 
}
 
void filter_off(DBE dbe) {
filtering off
refresh m
 
}
 
//---------------------------------------------------------------------
// main
 
DB b = create((NLS_("Domain Search Tool")), styleThemed|styleAutoparent)
 
uom = field(b, (NLS_("Units of Measure:")), (NLS_("<enter UOM to search>")), 31)
min = field(b, (NLS_("Range Minimum:")), (NLS_("<enter numeric value>")), 31)
max = field(b, (NLS_("Range Maximum:")), (NLS_("<enter numeric value>")), 31)
prec = field(b, (NLS_("Precision:")), (NLS_("<enter numeric value after \".\": ex: \".01\">")), 31)
//DBE englishPresentation = field(b, (NLS_("English Presentation:")), (NLS_("<enter English presentation:>")), 31)
 
button(b, (NLS_("Search")), create_filter)
button(b, (NLS_("Filter Off")), filter_off)
show b
 
//----------------------------------------------------------------------

I understand you want to combine the search criteria using &&. It might be a good idea to define come functions for the filter handling:
 

void addToFilter (Filter &dst, Filter addition) {
        if (null dst) dst = addition else dst = dst && addition 
    }
 
    // ... 
 
    Filter simple = null
 
    if (we_have_a_search_condition_for_units)
          addToFilter ( simple, contains(attribute "Format/Values", sUom, false) )
 
    if (we_have_a_search_condition_for_max) 
          addToFilter (simple, ... )

 


Regards, Mathias

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

Re: Error when leaving field blank or default
vppatel - Thu May 13 09:56:36 EDT 2010

Mathias Mamsch - Thu May 13 07:58:34 EDT 2010

I understand you want to combine the search criteria using &&. It might be a good idea to define come functions for the filter handling:
 

void addToFilter (Filter &dst, Filter addition) {
        if (null dst) dst = addition else dst = dst && addition 
    }
 
    // ... 
 
    Filter simple = null
 
    if (we_have_a_search_condition_for_units)
          addToFilter ( simple, contains(attribute "Format/Values", sUom, false) )
 
    if (we_have_a_search_condition_for_max) 
          addToFilter (simple, ... )

 


Regards, Mathias

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

thanks, I'll try that out.

Re: Error when leaving field blank or default
vppatel - Thu May 13 14:59:29 EDT 2010

Mathias Mamsch - Thu May 13 07:58:34 EDT 2010

I understand you want to combine the search criteria using &&. It might be a good idea to define come functions for the filter handling:
 

void addToFilter (Filter &dst, Filter addition) {
        if (null dst) dst = addition else dst = dst && addition 
    }
 
    // ... 
 
    Filter simple = null
 
    if (we_have_a_search_condition_for_units)
          addToFilter ( simple, contains(attribute "Format/Values", sUom, false) )
 
    if (we_have_a_search_condition_for_max) 
          addToFilter (simple, ... )

 


Regards, Mathias

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

got it to work by doing the following, thanks for the input

//global variable
string sUom
string sMin
string sMax
string sPrec
 
DBE uom
DBE min
DBE max
DBE prec
 
Module m = current
//func declaration
 
void create_filter(DBE dbe) {
 
    sUom = get uom
        sMin = get min
        sMax = get max
        sPrec = get prec
        
//check how to see if filter type is empty
        Filter simple = null
 
        if ((sUom != "<enter UOM to search>") && (sUom != null))
        {
                simple = contains(attribute "Format/Values", sUom, false) && contains(attribute "Object Text", sUom, false)
        }
        
        //if a user input a min value
        if ((sMin != "<enter numeric value>") && (sMin != null)) 
        {
                //add user min value to filter
                if (simple == null)
                {
                        simple = contains(attribute "Format/Values", sMin, false) && contains(attribute "Object Text", sMin, false)
                }
                else //simple indicates filter
                {
                        simple = simple && (contains(attribute "Format/Values", sMin, false) && contains(attribute "Object Text", sMin, false))             
                }
        }
                
        if ((sMax != "<enter numeric value>") && (sMax != null))
        {
                        //add user max value to filter                  
                        if (simple == null)
                        {                            
                                simple = contains(attribute "Format/Values", sMax, false) && contains(attribute "Object Text", sMax, false)                         
                        }
                        else //simple indicates filter
                        {                            
                                simple = simple && (contains(attribute "Format/Values", sMax, false) && contains(attribute "Object Text", sMax, false))
                        }    
 
        }    
        
        if ((sPrec != "<enter numeric value after \".\": ex: \".01\">") && (sPrec != null))
        {
                        //add user Prec value to filter
                        if (simple == null)
                        {
                                simple = contains(attribute "Format/Values", sPrec, false) && contains(attribute "Object Text", sPrec, false)
                        }
                        else //simple indicates filter
                        {
                                simple = simple && (contains(attribute "Format/Values", sPrec, false) && contains(attribute "Object Text", sPrec, false))
                        }
                
        }
 
        set simple
        filtering on
        applyFiltering (m)
        refresh m
 
        print("Done")
 
 
 
}
 
void filter_off(DBE dbe) {
        filtering off
        refresh m
 
}
 
//---------------------------------------------------------------------
// main
 
 
DB b = create((NLS_("Domain Search Tool")), styleThemed|styleAutoparent)
 
uom = field(b, (NLS_("Units of Measure:")), (NLS_("<enter UOM to search>")), 31)
min = field(b, (NLS_("Range Minimum:")), (NLS_("<enter numeric value>")), 31)
max = field(b, (NLS_("Range Maximum:")), (NLS_("<enter numeric value>")), 31)
prec = field(b, (NLS_("Precision:")), (NLS_("<enter numeric value after \".\": ex: \".01\">")), 31)
//DBE englishPresentation = field(b, (NLS_("English Presentation:")), (NLS_("<enter English presentation:>")), 31)
 
button(b, (NLS_("Search")), create_filter)
button(b, (NLS_("Filter Off")), filter_off)
show b
//----------------------------------------------------------------------